package pers.yurwisher.rubick.manager.service.impl;

import cn.hutool.core.lang.Assert;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import pers.yurwisher.rubick.common.base.impl.BaseServiceImpl;
import pers.yurwisher.rubick.common.wrapper.PageR;
import pers.yurwisher.rubick.manager.entity.SystemClient;
import pers.yurwisher.rubick.manager.mapper.SystemClientMapper;
import pers.yurwisher.rubick.manager.pojo.fo.SystemClientFo;
import pers.yurwisher.rubick.manager.pojo.qo.SystemClientQo;
import pers.yurwisher.rubick.manager.pojo.to.SystemClientTo;
import pers.yurwisher.rubick.manager.pojo.vo.SystemClientVo;
import pers.yurwisher.rubick.manager.service.ISystemClientService;

/**
 * @author yq
 * @date 2021-04-22 15:09:29
 * @description system client
 * @since V1.0.0
 */
@Service
public class SystemClientServiceImpl extends BaseServiceImpl<SystemClientMapper, SystemClient> implements ISystemClientService {

    /**
     * 新增
     *
     * @param fo 参数
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void create(SystemClientFo fo) {
        SystemClient systemClient = new SystemClient();
        BeanUtils.copyProperties(fo, systemClient);
        baseMapper.insert(systemClient);
    }

    /**
     * 更新
     *
     * @param id 主键
     * @param fo 参数
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void update(Long id, SystemClientFo fo) {
        SystemClient systemClient = baseMapper.selectById(id);
        Assert.notNull(systemClient);
        BeanUtils.copyProperties(fo, systemClient);
        baseMapper.updateById(systemClient);
    }

    /**
     * 列表
     *
     * @param qo 查询参数
     * @return 分页对象
     */
    @Override
    @SuppressWarnings("unchecked")
    public PageR<SystemClientTo> list(SystemClientQo qo) {
        return super.toPageR(baseMapper.list(super.toPage(qo), qo));
    }


    /**
     * 详情
     *
     * @param id 主键
     * @return SystemClientVo
     */
    @Override
    public SystemClientVo get(Long id) {
        return baseMapper.get(id);
    }

    /**
     * 删除
     *
     * @param id 主键
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delete(Long id) {
        baseMapper.deleteById(id);
    }
}
